﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;

public class lists : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";


        string id = "1";


        if (string.IsNullOrEmpty(id))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        id = HttpContext.Current.Request.Params["id"];
        var code = 1;
        var msg = "获取成功";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

                    Uri uri = HttpContext.Current.Request.Url;
    String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
            int _id = int.Parse(id);
            var news = bll.L_Newss.SingleOrDefault(x => x.NID == _id);//全部.ToList();



          var data = new
            {
                  news.Title,
                  news.Time,
                  
                  Content =news.Content.Replace("src=\"/upload/","src=\""+host+"/upload/"),
            };


            context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time,data}));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable {
        get {
            return false;
        }
    }




}